package com.oa.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.oa.bean.Section;
import com.oa.dao.DeptDao;
import com.oa.service.DeptService;

@Service
public class DeptServiceImpl implements DeptService {

	@Autowired
	DeptDao deptDao;
	
	@Override
	@Transactional
	public String addDept(Section section) {
		// TODO Auto-generated method stub
		Integer result = deptDao.insertDept(section);
		//修改状态
		System.out.println(result);
		Map<String,Object> map = new HashMap<>();
		
			map.put("deptno", section.getSeorid());
			map.put("role", 1);
			map.put("username", section.getSeprinid());
			System.out.println(map);
			Integer result2 = deptDao.updateUserDeptno(map);
			if(result2!=0){
				return "true";
			}
		
		
		
		return "false";
	}

	@Override
	public List<Section> getDeptList() {
		// TODO Auto-generated method stub
		List<Section> list = deptDao.selectDeptList();
		return list;
	}

	@Override
	public String changeDept(Section section) {
		// TODO Auto-generated method stub
		Integer result = deptDao.updateDeptBySection(section);
		System.out.println(result);
		if(result!=0){
			return "true";
		}
		return "false";
	}

}
